#! /usr/bin/env node

//引入文件模块
const fs = require("fs");

//引入路径模块
const path = require("path");

//引入进程模块
const process = require("process");

// 引入随机颜色模块
const chalk = require("chalk");

//当前目录
const processPath = process.cwd()

//找路径
const dataPath = path.join(__dirname, './data');

//读取所有文件名称
const fileNames = fs.readdirSync(dataPath).map(item => item.replace(".txt", ""));

//命令行参数
let argvName = process.argv[2];
argvName = fileNames.includes(argvName) ? argvName : "tangshi";

//截取key
const splitKey = argvName === "animals" ? "===============++++SEPERATOR++++====================" : "%";

//读取当前文件的所有文章
const articles = fs.readFileSync(path.join(dataPath, argvName + ".txt"),"utf-8").split(splitKey);

//随机数函数
const getRandom = (max, min) => Math.floor(Math.random() * (max - min + 1));

//随机文章
const getArt = articles[getRandom(articles.length, 0)];


console.log(chalk.rgb(getRandom(255, 0), getRandom(255, 0), getRandom(255, 0))(getArt));
